<template>
  <div>
    <Header :left="true" leftText="返回" title="加严管控详情"> </Header>
    <div>
      <div class="textScroll">
        <!-- 循环数据开始 -->
        <div style="height: 50px;padding-top: 8px;">
          <van-button v-if="showBtn"
                color="#138087"
                @click.stop="confirmmessage"
                style="
                  width: 85px;
                  height: 40px;
                  font-size: 12px;
                
                "
                type="primary"
                text="确认"/>
        </div>
        
        <div v-for="item in itemsOne" :key="item.id">
          <div style="width: 100%; background-color: #f3f4f8; height: 5px">
            <span></span>
          </div>
          <div class="divStyle">
            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>加严说明:</b></van-col>
              <van-col span="14">{{ item.StrictDescription }}</van-col>
            </van-row>

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>加严类型:</b></van-col>
              <van-col span="14">{{
                showAddStrictTypeName(item.StrictTypeID)
              }}</van-col>
              <!-- <van-button
                color="#138087"
                @click.stop="confirmmessage(item)"
                style="
                  width: 85px;
                  height: 40px;
                  font-size: 12px;
                  position: absolute;
                  left: 80%;
                "
                type="primary"
                text="选择"
              /> -->
            </van-row>

            <!-- <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>建议等级:</b></van-col>
              <van-col span="14">{{ showABCTypeName(item.ABCType) }}</van-col>
            </van-row>
            <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="6"><b>判断等级:</b></van-col>
            <van-col span="14">{{
              showABCTypeName(addStrictManage.ABCType)
            }}</van-col>
          </van-row> -->

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>生产线:</b></van-col>
              <van-col span="14">{{ item.PLineID }}</van-col>
            </van-row>

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>生产订单:</b></van-col>
              <van-col span="14">{{ showPOrderIDName(item.POrderID) }}</van-col>
            </van-row>

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>加严开始时间:</b></van-col>
              <van-col span="14">{{ item.FromDatetime }}</van-col>
            </van-row>

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"><b>创建者:</b></van-col>
              <van-col span="14">{{ item.Creator }}</van-col>
            </van-row>

            <van-row style="margin-left: 10px; margin-top: 10px">
              <van-col span="6"> </van-col>
              <van-col span="3"> </van-col>
              <van-col span="6"> </van-col>
            </van-row>
          </div>
        </div>
        <!-- 循环数据结束 -->
        <!-- <van-empty v-if="itemsOne == ''" image="search" description="暂无数据" /> -->
      </div>
    </div>
  </div>
</template>

<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { _httpClient } from "@/libs/apisie";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "heyu5",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      showBtn:true,
      columnsPOrderID: [],
      columnsStrictTypeID: [
      { StrictTypeID: "SM01", StrictTypeName: "关键工艺参数异常加严" },
        { StrictTypeID: "SM02", StrictTypeName: "机器设备异常加严" },
        { StrictTypeID: "SM03", StrictTypeName: "质量异常加严" },
        { StrictTypeID: "SM04", StrictTypeName: "生产条件异常加严" },
      ],
      columnsABCType: [
        { ABCType: "1", ABCTypeName: "甲" },
        { ABCType: "2", ABCTypeName: "乙" },
        { ABCType: "3", ABCTypeName: "丙" },
        { ABCType: "4", ABCTypeName: "-未确定" },
      ],
      showPickerpline: false,
      itemsOne: [],
      item: {},
      plineId:"",
      form: {},
      query: {
        FactoryID: "",
        Required: "",
        StrictDescription: "",
        Closed: false,
        ClosedName: "否",
      },
      columnspline: [
        { plineId: true, plineName: "是" },
        { plineId: false, plineName: "否" },
      ],
    };
  },

  created: function () {
    this.item = api.pageParam.item;
    this.item.Checked = false;
    this.form = api.pageParam.form;
    this.isAdd = api.pageParam.isAdd;
    this.plineId=api.pageParam.machineId
    this.getUncheckedList();
    this.getPOrderID();
  },
  async mounted() {},

  methods: {
    showPOrderIDName(POrderID) {
      var POrderIDName = POrderID;
      this.columnsPOrderID.forEach((item) => {
        if (item.POrderID === POrderID) {
          POrderIDName = item.POrderIDAndMaterialName;
        }
      });
      return POrderIDName;
    },
    showABCTypeName(ABCType) {
      var ABCTypeName = ABCType;
      this.columnsABCType.forEach((item) => {
        if (item.ABCType === ABCType) {
          ABCTypeName = item.ABCTypeName;
        }
      });
      return ABCTypeName;
    },
    showAddStrictTypeName(AddStrictType) {
      var AddStrictTypeName = AddStrictType;
      this.columnsStrictTypeID.forEach((item) => {
        if (item.StrictTypeID === AddStrictType) {
          AddStrictTypeName = item.StrictTypeName;
        }
      });
      return AddStrictTypeName;
    },

    async getPOrderID() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/MachineCurrentPOrder/GetList"
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            POrderID: item.POrderID,
            MaterialName: item.MaterailName,
            MaterialID: item.MaterailID,
            POrderIDAndMaterialName: item.POrderID + " " + item.MaterailName,
          }));
          _this.columnsPOrderID = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmpline(value, index) {
      this.query.Closed = this.columnspline[index].plineId;
      this.query.ClosedName = this.columnspline[index].plineName;
      this.showPickerpline = false;
    },
    //确认
    async confirmmessage() {
      let _this = this;

     api.sendEvent({
        name: 'flush-close-00',
        extra: {
            itemsOne:this.itemsOne 
        }
        
    });
      setTimeout(function () {
        _this.$ac.closeWin();
      }, 1000);
    },
    //查询未确审核调机数据
    async getUncheckedList() {
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
            "/AddStrictManage/GetPageList?PageSize=100&PageIndex=1&FactoryID=" +
            this.query.FactoryID +
            "&Required=" +
            this.query.Required +
            "&StrictDescription=" +
            this.query.StrictDescription +
            "&Closed=" +
            this.query.Closed+
            "&PLineID="+this.plineId
        );
        // if (res.Total == 0) {
        //   Toast.clear();
        // } else {
        Toast.clear();
        _this.itemsOne = res.Data;

        // alert(JSON.stringify(res.Data[0]))
        if(res.Data.length==0){
          Toast(this.plineId+" 没有加严项，无法关闭")
          this.showBtn=false
          return
        }
        for(let i =0;i<res.Data.length;i++){
          let item=res.Data[i]
          if(item.Comfirmed==false){
            this.showBtn=false
            Toast(this.plineId+" 还有处于未判定的加严项，无法关闭")
            break
          }
        }
        //}
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
  },
};
</script>

<style>
.message {
  font-size: 20px;
  margin-top: 10px;
  margin-left: -10px;
  font-weight: bold;
}
</style>
